package de.tapps.brainstorming;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.MalformedURLException;
import java.net.URL;

import android.os.AsyncTask;

/**
 * Reads the updates and shows it as a notification
 * 
 * @author Timo
 * Decrypted - ok
 */
public class UpdateCheck extends AsyncTask<String, Integer, String> {
	private MainActivity activity = new MainActivity();

	public UpdateCheck(MainActivity act){
		activity = act;
		

	}
	
	
	@Override
	protected String doInBackground(String... arg0) {
		new Thread(new Runnable() {
			public void run() {
				URL url = null;

				
				try {
					url = new URL(
							"http://t-apps-online.de/BrainStorming/updateMessage.php");
					String readLine = null;
					BufferedReader buffReader = new BufferedReader(
							new InputStreamReader(url.openStream()));
					
					while ((readLine = buffReader.readLine()) != null) {
						activity.showNotification(readLine);
					}
				} catch (MalformedURLException me) {
					me.printStackTrace();
				} catch (IOException ioe) {
					ioe.printStackTrace();
				}
			
			
			}
		}).start();
		return null;
	}
}
